package cn.sccl.common.util;

import cn.sccl.common.controller.OperationLogController;
import cn.sccl.common.model.OperationLog;
import cn.sccl.dirms.enumConst.OperationTypeEnum;

/**
 * 操作日志工具类
 * Created by 贺 强 on 2016/3/23.
 */
public class OperationLogUtil {


    /**
     * 创建操作日志(包含操作详情)
     *
     * @param userName      当前操作用户名
     * @param operationType 操作类型（登录、登出……）
     * @param details       操作详情
     * @return
     */
    public static boolean createOperationLog(String userName, OperationTypeEnum operationType, String details) {
        // 获取日志存取控制器
        OperationLogController controller = (OperationLogController) SpringUtils.getSpringBean("operationLogController");

        // 创建操作日志
        OperationLog operationLog = new OperationLog();
        operationLog.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));
        operationLog.setUserName(userName);
        operationLog.setType(operationType.getValue().longValue());
        operationLog.setDetails(details);

        // 保存操作日志
        controller.saveOperationLog(operationLog);

        return true;
    }

    /**
     * 创建操作日志（缺省操作详情）
     *
     * @param userName      当前操作用户
     * @param operationType 操作类型
     * @return
     */
    public static boolean createOperationLog(String userName, OperationTypeEnum operationType) {
        // 获取日志存取控制器
        OperationLogController controller = (OperationLogController) SpringUtils.getSpringBean("operationLogController");

        // 创建操作日志
        OperationLog operationLog = new OperationLog();
        operationLog.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));
        operationLog.setUserName(userName);
        operationLog.setType(operationType.getValue().longValue());

        // 保存操作日志
        controller.saveOperationLog(operationLog);

        return true;
    }

}
